/*
 * Kaka JavaScript FrameWork
 * http://www.rayteen.com/
 *
 * 作者：路卡卡
 * 联系方式：1599538531@qq.com
 * Version：1.0
 * 日期：2012/2/24
 *
 * 访问 http://www.rayteen.com/ 获取最新版本
*/
(function(window){
	var kaka = {},
	  	document = window.document,
		navigator = window.navigator,
		// 用户代理
		userAgent = navigator.userAgent.toLowerCase(),
		// 匹配ID选择器
		matId = /^\s*#{1}([a-zA-Z]{1,}[\w_]*)/,
		// 匹配class选择器
		matClass = /^\s*\.{1}([a-zA-Z]{1,}[\w_]*)/,
		// 分割选择器
		matChar = /\s*,\s*/,
		// 匹配HTML格式字符
		matHtml = /^<([a-zA-Z]+)(\s+([a-zA-Z]+)=['|"]+(.*)['|"]+)*>.*(<\/[a-zA-Z]+>)$/,
		// 匹配HTML标签
		matTag = "div|img|span|p|a|strong|b|h1|h2|h3|h4|h5|h6|ul|li|ol|table|thead|tbody|tfoot|tr|td|form|input|select|option|button|textarea|u|s|i|html|body|head|title",
		tagExp = new RegExp("^(" + matTag + ")$","i");

/*
* ============ selector ============
*/ 
	kaka.$selector = {
		// 匹配选择器
		matchSelector : function( str ){
			if( str.match( matId ) ){
				return [this.getById( RegExp.$1 )];
			}else if( str.match( matClass ) ){
				return this.getByClass( RegExp.$1 );
			}else if( str.match( tagExp ) ){
				return this.getByTag( RegExp.$1 );
			}else{
				return null;
			};
		},
		/*
		*  @ 获取对象
		*/ 
		get : function( element ){
			var res = [];
			if( typeof element === 'string' ){
				var els = element.split( matChar );
				for( var i = 0 , len = els.length ; i < len ; i++ ){
					var cur = els[i],
						matRes = this.matchSelector(cur);
					if( matRes ){
						res = res.concat(matRes);
					};
				};
			}else{
				if( element.tagName ){
					return [this.getById(element)];
				}else if( element.item ){
					return this.getByTag(element);
				}else if( element instanceof Array ){
					return element;
				};
			};
			return res;
		},
		/*
		*  @ 通过元素ID获取DOM对象
		*/ 
		getById : function( element ){
			if( typeof element === 'string' && element !== '' ) return document.getElementById(element);
			return element;
		},
		/*
		*  @ 通过元素Class获取DOM对象
		*/ 
		getByClass : function( str ){
			if( typeof str !== 'string' || str === '' ){ return };
			if( document.getElementsByClassName ){
				return this.getByTag( document.getElementsByClassName(str) );
			}else{
	  			var els = document.all ? document.all : document.getElementsByTagName("*"),
	  				res = [];
				for( var i = 0 , len = els.length ; i < len; i++ ){
					var cur = els[i], curClass = cur.className,
						regStr = "\\b" + str + "\\b",
						reg = new RegExp(regStr,"g");
					if( reg.test(curClass) ){
						res.push(cur);
					};
				};
				return res;
			};
		},
		/*
		*  @ 通过元素名获取DOM对象
		*/ 
		getByTag : function( element ){
			var res = [];
			if( element.item ){
				for( var i = 0 , len = element.length ; i < len ; i++ ){
					res.push( element[i] );
				};
			}else if( typeof element === "string" && tagExp.test(element) ){
				return this.getByTag( document.getElementsByTagName(element) );
			};
			return res;
		},
		/*
		*  @ 获取下一个元素
		*/
		next : function( element ){
			var obj = $selector.get(element), len = obj.length, res = [];
			if( !len ){ return res };
			for( var i = 0 ; i < len ; i++ ){
	  			var cur = obj[i], next = cur.nextSibling;
	  			if( !next ){ continue };
				while( next.nodeType != 1 ){
					next = next.nextSibling;
					if( !next ){ break };
				};
				if( next ){ res.push(next) };
			};
			return len == 1 ? res[0] : res;
		},
		/*
		*  @ 获取匹配元素之后的所有同辈元素
		*/
		nextAll : function( element ){
			var obj = $selector.get(element), res = [];
			if( !obj.length ){ return res };
			for( var i = 0 , len = obj.length ; i < len ; i++ ){
				var cur = obj[i],
					index = $dom.index(cur),
					parent = this.parent(cur),
					child = this.children(parent),
					childLen = child.length;
				if( index != (childLen - 1) ){
					var singRes = child.slice( index + 1,childLen );
					res = res.concat(singRes);
				};
			};
			return res;
		},
		/*
		*  @ 获取上一个元素
		*/
		prev : function( element ){
			var obj = $selector.get(element), len = obj.length, res = [];
			if( !len ){ return res };
			for( var i = 0 ; i < len ; i++ ){
	  			var cur = obj[i], prev = cur.previousSibling;
	  			if( !prev ){ continue };
				while( prev.nodeType != 1 ){
					prev = prev.previousSibling;
					if( !prev ){ break };
				};
				if( prev ){ res.push(prev) };
			};
			return len == 1 ? res[0] : res;
		},
		/*
		*  @ 获取匹配元素之前的所有同辈元素
		*/
		prevAll : function( element ){
			var obj = $selector.get(element), res = [];
			if( !obj.length ){ return res };
			for( var i = 0 , len = obj.length ; i < len ; i++ ){
				var cur = obj[i],
					index = $dom.index(cur),
					parent = this.parent(cur),
					child = this.children(parent),
					childLen = child.length;
				if( index != 0 ){
					var singRes = child.slice(0,index);
					res = res.concat(singRes);
				};
			};
			return res;
		},
		/*
		*  @ 获取同辈元素
		*/
		siblings : function( element ){
			var obj = $selector.get(element), res = [];
			if( !obj.length ){ return res };
			for( var i = 0 , len = obj.length ; i < len ; i++ ){
				var cur = obj[i];
				res = res.concat( this.prevAll(cur).concat( this.nextAll(cur) ) );
			};
			return res;
		},
		/*
		*  @ 获取元素的父级元素
		*/
		parent : function( child ){
			var obj = $selector.get(child), res = [];
			if( !obj.length ){ return res };
			for( var i = 0 , len = obj.length ; i < len ; i++ ){
				var cur = obj[i], par = cur.parentNode;
				while( par.nodeType != 1 ){
					par = par.parentNode;
				};
				res.push(par);
			};
			return res;
		},
		/*
		*  @ 获取匹配元素的子元素
		*/
		children : function( parent ){
			var obj = $selector.get(parent), res = [];
			if( !obj.length ){ return res };
			for( var i = 0 , len = obj.length ; i < len ; i++ ){
				var cur = obj[i], child = cur.childNodes;
				for( var j = 0 , jLen = child.length ; j < jLen ; j++ ){
	  				if( child[j].nodeType == 1 ){
	  					res.push(child[j]);
	  				};
				};
			};
			return res;
		},
		/*
		*  @ 获取匹配元素的第一个元素
		*/
		first : function( parent ){
			var obj = $selector.get(parent);
			if( !obj.length ){ return};
			return obj[0];
		},
		/*
		*  @ 获取匹配元素的最后一个元素
		*/
		last : function( parent ){
			var obj = $selector.get(parent);
			if( !obj.length ){ return };
			return obj[obj.length - 1];
		}
	};
	
/*
* ============ class ============
*/ 
	kaka.$className = {
		/*
		*  @ 检查当前的元素是否含有某个特定的类
		*/
		hasClass : function( element,classname ){
			var doEle = $selector.get(element);
			if( !doEle.length || !classname ){ return };
			// 若传入的是一个DOM元素数组，则取第一个
			return new RegExp("\\b"+classname+"\\b","g").test(doEle[0].className);
		},
		/*
		*  @ 为每个匹配的元素添加指定的类名
		*/
		addClass : function( el,name ){
			var obj = $selector.get(el);
			if( !obj.length || !name ){ return };
			for( var i = 0 , len = obj.length ; i < len ; i++ ){
				var cur = obj[i],
					curClass = cur.className,
					regCla = new RegExp("\\b(" + name + ")\\b"),
					mat = curClass.match(regCla);
				if( !mat ){
					cur.className += " " + name;
				};
			};
			return obj;
		},
		/*
		*  @ 从所有匹配的元素中删除全部或者指定的类
		*/
		removeClass : function( el,name ){
			var obj = $selector.get(el), RemoveAll = false;
			if( !obj.length ){ return };
			// 无name参数则删除所有的类
			if( typeof name === 'undefined' ){ RemoveAll = true };
			for( var i = 0 , len = obj.length ; i < len ; i++ ){
				var cur = obj[i],
					curClass = cur.className,
					regCla = new RegExp("\\s*\\b(" + name + ")\\b"),
					mat = curClass.match(regCla);
				if( RemoveAll ){
					cur.className = '';
				}else{
					if( mat ){
						cur.className = curClass.replace(regCla,"");
					};
				};
			};
			return obj;
		},
		/*
		*  @ 存在（不存在 ）就删除（增加）一个类
		*/
		toggleClass : function( el,name ){
			var obj = $selector.get(el);
			if( !obj.length || !name ){ return };
			for( var i = 0 , len = obj.length ; i < len ; i++ ){
				var cur = obj[i],
					curClass = cur.className,
					regCla = new RegExp("\\s*\\b(" + name + ")\\b"),
					mat = curClass.match(regCla);
				if( mat ){
					cur.className = curClass.replace(regCla,"");
				}else{
					cur.className += " " + name;
				}
			};
			return obj;
		}
		
	};
/*
* ============ text ============
*/ 
	kaka.$text = {
		/*
		*  @ 获取匹配元素的文本内容
		*/
		get : function( element ){
			var el = $selector.get(element);			
			if( !el.length ){ return };
			for( var i = 0 , len = el.length , res = [] ; i < len ; i++ ){
				var cur = el[i];
				res.push( cur.innerText || cur.textContent );
			};
			return res.join('');
		},
		/*
		*  @ 设置匹配元素的文本内容
		*/
		set : function( element,str ){
			var el = $selector.get(element);			
			if( !el.length || typeof str == 'undefined' ){ return };
			for( var i = 0 , len = el.length ; i < len ; i++ ){
				var cur = el[i];
				cur.innerText ? cur.innerText = str : cur.textContent = str;
			};
			return el;
		}
	};
/*
* ============ html ============
*/ 
	kaka.$html = {
		/*
		*  @ 获取匹配元素的HTML内容
		*/ 
		get : function( element ){
			var el = $selector.get(element);			
			if( !el.length ){ return };
			return el[0].innerHTML;
		},
		/*
		*  @ 设置匹配元素的HTML内容
		*/ 
		set : function( element,str ){
			var el = $selector.get(element);			
			if( !el.length || typeof str == 'undefined' ){ return };
			for( var i = 0 , len = el.length ; i < len ; i++ ){
				el[i].innerHTML = str;
			};
			return el;
		}
	};
/*
* ============ val ============
*/ 
	kaka.$val = {
		/*
		*  @ 获取匹配表单元素的value值
		*/ 
		get : function( element ){
			var el = $selector.get(element),
				matInput = /input|textarea/;
			if( !el.length ){ return };
			if( matInput.test(el.tagName.toLowerCase()) ){
				return el[0].value;
			};
		},
		/*
		*  @ 设置匹配表单元素的value值
		*/ 
		set : function( element,str ){
			var el = $selector.get(element),
				matInput = /input|textarea/;
			if( !el.length || typeof str == 'undefined' ){ return };
			for( var i = 0 , len = el.length ; i < len ; i++ ){
				var cur = el[i];
				if( matInput.test(cur.tagName.toLowerCase()) ){
					cur.value = str;
				};
			};
			return el;
		}
	};
/*
* ============ Dom ============
*/ 
	kaka.$dom = {
		/*
		*  @ 获取匹配元素的索引
		*/
		index : function( element ){
			var obj = $selector.get(element);
			if( !obj.length ){ return };
			// 多元素则返回第一个元素的索引
			obj = obj[0];
			var	p = $selector.parent(obj)[0],
				c = $selector.children(p),
				len = c.length;
			for( var i = 0 ; i < len ; i++ ){
				var cur = c[i];
				if( cur == obj ){
					return i;
				};
			};
		},
		/*
		*  @ 获取匹配元素的个数
		*/
		size : function( obj ){
			var obj = $selector.get(obj);
			return obj.length;
		},
		/*
		*  @ 向所有匹配的元素尾部插入内容
		*/
		append : function( target,todo ){
			var toDeal = $selector.get(target);
			if( !toDeal.length ){ return };
			if( toDeal.length == 1 ){
				this._sinAppend( toDeal[0],todo );
			}else{
				for( var i = 0 , len = toDeal.length ; i < len ; i++ ){
					this._sinAppend( toDeal[i],todo );
				};
			};
			return toDeal;
		},
		_sinAppend : function( element,todo ){
			if(typeof todo === 'string' && todo != ''){
				element.innerHTML += todo;
			}else if( todo instanceof Object ){
				element.appendChild(todo);
			};
		},
		/*
		*  @ 向所有匹配的元素头部插入内容
		*/
		prepend : function( target,todo ){
			var toDeal = $selector.get(target);
			if( !toDeal.length ){ return };
			if( toDeal.length == 1 ){
				this._sinPrepend( toDeal[0],todo );
			}else{
				for( var i = 0 , len = toDeal.length ; i < len ; i++ ){
					this._sinPrepend( toDeal[i],todo );
				};
			};
			return toDeal;
		},
		_sinPrepend : function( element,todo ){
			if(typeof todo == 'string' && todo != ''){
				element.innerHTML = todo + element.innerHTML;
			}else if( todo instanceof Object ){
				element.insertBefore( todo,element.firstChild );
			};
		},
		/*
		*  @ 向所有匹配的元素前面插入DOM
		*/
		insertBefore : function( element,todo ){
			var toDeal = $selector.get(element);
			if( !toDeal.length ){ return };
			if( toDeal.length == 1 ){
				this.parent(toDeal).insertBefore(todo,toDeal);
			}else{
				for( var i = 0,len = toDeal.length ; i < len ; i++ ){
					var cur = toDeal[i];
					this.parent(cur).insertBefore(todo.cloneNode(true),cur);
				};
				this.remove(todo);
			};
			return toDeal;
		},
		/*
		*  @ 向所有匹配的元素后面插入DOM
		*/
		insertAfter : function( element,todo ){
			var toDeal = $selector.get(element);
			if( !toDeal.length ){ return };
			for( var i = 0 , len = toDeal.length ; i < len ; i++ ){
				var curNum = i + 1, 
					cur = toDeal[curNum];
				if( curNum < len ){
					this.parent(cur).insertBefore(todo.cloneNode(true),cur);
				}else{
					this.append( this.parent(toDeal[curNum-1]),todo.cloneNode(true) );
				};
			};
			this.remove(todo);
			return toDeal;
		},
		/*
		*  @ 在匹配的元素前面插入一些HTML标记代码
		*/
		before : function( element,todo ){
			if( typeof todo === 'string' ){
				var mat = todo.match(matHtml);
				if( mat ){
					var toDeal = $selector.get(element),
						tagName = mat[1],
						staIndex = todo.indexOf(tagName) + tagName.length;
					if( !toDeal.length ){ return };
					// 检测是否设置元素特性
					if( mat[2] ){
						staIndex = todo.indexOf(tagName) + tagName.length + mat[2].length;
					};
					var endIndex = todo.lastIndexOf(tagName),
						htmlText = todo.substring(staIndex+1,endIndex-2),
						newElement = document.createElement(tagName);
					newElement.innerHTML = htmlText;
					// 检测是否存在元素特性值
					if( mat[3] && mat[4] ){
						this.attr(newElement,mat[3],mat[4]);
					};
					// 是否批量
					if( toDeal.length == 1 ){
						this.parent(toDeal).insertBefore(newElement,toDeal);
					}else{
						for( var i = 0 , len = toDeal.length ; i < len ; i++ ){
							var cur = toDeal[i],
								clone = newElement.cloneNode(true);
							this.parent(cur).insertBefore(clone,cur);
						};
					};
					return toDeal;
				};
			};
		},
		/*
		*  @ 在匹配的元素后面插入一些HTML标记代码
		*/
		after : function( element,todo ){
			if( typeof todo === 'string' ){
				var mat = todo.match(matHtml);
				if( mat ){
					var toDeal = $selector.get(element),
						tagName = mat[1],
						staIndex = todo.indexOf(tagName) + tagName.length;
					if( !toDeal.length ){ return };
					// 检测是否设置元素特性
					if( mat[2] ){
						staIndex = todo.indexOf(tagName) + tagName.length + mat[2].length;
					};
					var endIndex = todo.lastIndexOf(tagName),
						htmlText = todo.substring(staIndex+1,endIndex-2),
						newElement = document.createElement(tagName);
					newElement.innerHTML = htmlText;
					// 检测是否存在元素特性值
					if( mat[3] && mat[4] ){
						this.attr(newElement,mat[3],mat[4]);
					};
					// 是否批量
					if( toDeal.length == 1 ){
						this.insertAfter(toDeal,newElement);
					}else{
						for( var i = 0 , len = toDeal.length ; i < len ; i++ ){
							var cur = toDeal[i],
								index = this.index(cur),
								parent = this.parent(cur),
								child = this.children(parent);
							var	clone = newElement.cloneNode(true);
							parent.insertBefore(clone,child[index+1]);
						};
					};
					return toDeal;
				};
			};
		},
		/*
		*  @ 删除节点
		*/
		remove : function( nodes ){
			var obj = $selector.get(nodes);
			if( !obj.length ){ return };
			if( obj.length == 1 ){
				var parent = this.parent(obj[0]);
				parent.removeChild(obj[0]);
			}else{
				for(var i = 0,len = obj.length;i < len;i++){
					var cur = obj[i],
						parent = this.parent(cur);
					parent.removeChild(cur);
				};
			};
			return obj;
		}
	};
/*
* ============ data ============
*/ 
	kaka.$data = {
		/*
		*  @ 在元素上存放数据
		*/ 
		get : function( element,name ){
			var el = $selector.get(element)[0];
			return el.stor ? el.stor[name] : 'undefined';
		},
		/*
		*  @ 设置在元素上存放的数据
		*/ 
		set : function( element,name,value ){
			var el = $selector.get(element)[0];
			el.stor = el.stor || {};
			el.stor[name] = value;
			return el;
		}
	};
/*
* ============ event ============
*/ 
	kaka.$event = {
		/*
		*  @ 为每个匹配元素的特定事件绑定事件处理函数
		*/ 
		add : function( element,type,handler ){
			var element = $selector.get(element),
				len = element.length;
			if( !element.length ){ return };
			for( var i = 0 ; i < len ; i++ ){
				var cur = element[i];
				this._addHandler( cur,type,handler );
			};
			return element;
		},
		_addHandler : function( element,type,handler ){
			// 储存处理函数
			var evtHandler = '_' + type;
			element[evtHandler] = element[evtHandler] || [];
			element[evtHandler].push(handler);
			// bind
			if( element.addEventListener ){
				element.addEventListener( type,handler,false );
			}else{
				element["on" + type] = function(){
					if( !element[evtHandler].length ){ return };
					for( var i = 0 , len = element[evtHandler].length ; i < len ; i++ ){
						element[evtHandler][i].apply(element);
					};
				};
			};
		},
		/*
		*  @ 从每一个匹配的元素中删除绑定的事件
		*/ 
		remove : function( element,type,handler ){
			var element = $selector.get(element),
				len = element.length,
				evtHandler = '_' + type;
			if( !element.length ){ return };
			if( typeof handler != 'undefined' ){
				for( var i = 0 ; i < len ; i++ ){
					var cur = element[i];
					this._removeHandler( cur,type,handler );
				};
			}
			// 解除绑定在元素上的某一类特定事件
			else{
				for( var i = 0 ; i < len ; i++ ){
					var cur = element[i];
					// 标准解绑
					if( cur.removeEventListener ){
						for( var j = 0 , jLen = cur[evtHandler].length ; j < jLen ; j++ ){
							this._removeHandler( cur,type,cur[evtHandler][0] );	
						};
					}
					// IE解绑
					else{
						cur[evtHandler] = [];
					};
				};
			};
			return element;
		},
		_removeHandler : function( element,type,handler ){
			// 同时删除元素对象上储存的处理函数
			var evtHandler = '_' + type;
			if( element[evtHandler] ){
				$arr.remove( element[evtHandler],handler );
			};
			
			if( element.removeEventListener ){
				element.removeEventListener( type,handler,false );
			};
		},
		/*
		*  @ 在每一个匹配的元素上触发某类事件
		*/ 
		trigger : function( element,type,args ){
			var element = $selector.get(element), evtHandler = '_' + type, len = element.length;
			if( !len ){ return };
			for( var i = 0 ; i < len ; i++ ){
				var cur = element[i], jLen = cur[evtHandler] ? cur[evtHandler].length : 0;
				if( jLen ){
					for( var j = 0 ; j < jLen ; j++ ){
						args && args instanceof Array ? cur[evtHandler][j].apply(cur,args) : cur[evtHandler][j].apply(cur);
					};
				}else{
					continue
				};
			};
		}
	};
	
/*
* ============ 属性操作 ============
*/ 	
	kaka.$attr = {
		/*
		*  @ 获取匹配元素的特性值
		*/
		get : function( elem,name ){
			var el = kaka.selector.get( elem );
			if( !el.length || !name ){ return };
			// 针对IE6/7不支持class特性设置
			if( name === 'class' ){
				var div = document.createElement("div");
				div.setAttribute("class","test");
				name = div.className === 'test' ? name : 'className';
			};
			return el[0].getAttribute( name );
		},
		/*
		*  @ 设置匹配元素的特性值
		*/
		set : function( elem,name,value ){
			var el = kaka.selector.get( elem );
			if( !el.length || !name || typeof value === 'undefined' ){ return };
			// 针对IE6/7不支持class特性设置
			if( name === 'class' ){
				var div = document.createElement("div");
				div.setAttribute("class","test");
				name = div.className === 'test' ? name : 'className';
			};
			if( el.length == 1 ){
				el[0].setAttribute( name,value );
			}else{
				for( var i = 0 , len = el.length ; i < len ; i++ ){
					var cur = el[i];
					cur.setAttribute( name,value );
				};
			};
			return el;
		},
		/*
		*  @ 删除匹配元素的特性
		*/
		remove : function( el,name ){
			var obj = $selector.get(el);
			if( !obj.length || !name ){ return };
			// 针对IE6/7不支持class特性设置
			if(name === 'class'){
				var div = document.createElement("div");
				div.setAttribute("class","test");
				name = div.className === 'test' ? name : 'className';
			};
			if( obj.length == 1 ){
				var curAttr = obj.getAttribute(name);
				if( curAttr ){
					obj.removeAttribute(name);
				};
			}else{
				for(var i = 0,len = obj.length;i < len;i++){
					var cur = obj[i],
						curAttr = cur.getAttribute(name);
					if( curAttr ){
						cur.removeAttribute(name);
					};
				};
			};
			return obj;
		}
	};
/*
* ============ 样式操作 ============
*/ 
	kaka.$css = {
		/*
		*  @ 获取CSS值
		*/
		get : function( element,pro ){
			var el = $selector.get(element)[0], special = /^width|height$/;
			if( $browser.msie && special.test(pro) ){
	  			switch( pro ){
					case 'width' : return el.clientWidth + 'px';
					case 'height' : return el.clientHeight + 'px';
				};
			};
			var curStyle = this.getComputedStyle(el), fuckIE = /^medium$/;
			if( fuckIE.test(curStyle[pro]) ){
				return '0px'
			};
			return curStyle[pro];
		},
		/*
		*  @ 设置CSS值
		*/
		set : function( element,pro,val ){
			var el = $selector.get(element), len = el.length;
			if( !len || typeof val == 'undefined' ){ return };
			for( var i = 0 ; i < len ; i++ ){
				var cur = el[i];
				cur.style[pro] = val;
			};
			return el;
		},
		/*
		*  @ 插入带样式信息的style标签
		*/
		addStyle : function( str ){
			if( !str ){ return };
			var style = document.createElement('style');
			style.setAttribute('type','text/css');
			// 万恶的IE不支持标准写法
			if( style.styleSheet ){
				style.styleSheet.cssText = str;
			}else{
				var text = document.createTextNode(str);
				style.appendChild(text);
			};
			var head = document.getElementsByTagName('head');
			head.length ? head[0].appendChild(style) : document.documentElement.appendChild(style);
		},
		/*
		*  @ 取得元素对象的CSS样式声明对象
		*/
		getComputedStyle : function( element ){
			return window.getComputedStyle ? getComputedStyle(element,null) : element.currentStyle;
		}
	};
/*
* ============ 类型检测 ============
*/ 
	kaka.$check = {
		/* @ 对象检测 */
		isObject : function(obj){
			return obj instanceof Object;
		},
		/* @ 函数检测 */
		isFunction : function(obj){
			return obj.constructor == Function;
		},
		/* @ 数组检测 */
		isArray : function(obj){
			return obj.constructor == Array;
		},
		/* @ 数字型检测 */
		isNumber : function(obj){
			return typeof obj == 'number';
		},
		/* @ 字符串检测 */
		isString : function(obj){
			return typeof obj == 'string';
		},
		/* @ 布尔型检测 */
		isBoolean : function(obj){
			return typeof obj == 'boolean';
		},
		/* @ 空对象检测 */
		isEmpty : function(obj){
			for(var name in obj){
				return false;
			};
			return true;
		},
		/* @ 定义检测 */
		isDefined : function(obj){
			return typeof obj !== 'undefined';
		},
		/* @ Date对象检测 */
		isDate : function(obj){
			return obj instanceof Date;
		}
	};
/*
* ============ 浏览器检测（借用下jQ源码的正则 -. -） ============
*/ 
	kaka.$browser = {
		version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [])[1], 
		safari: /(webkit)[ \/]([\w.]+)/.test( userAgent ), 
		opera: /(opera)(?:.*version)?[ \/]([\w.]+)/.test( userAgent ), 
		msie:  /(msie) ([\w.]+)/.test( userAgent ) && !/opera/.test( userAgent ), 
		mozilla: /(mozilla)(?:.*? rv:([\w.]+))?/.test(userAgent)&&!/(compatible|webkit)/.test(userAgent)
	};
/*
* ============ cookie获取、设置 ============
*/ 
	kaka.$cookie = {
		/*
		*  @ cookie获取
		*  参数说明：cookie名称
		*  返回：指定cookie的值
		*/ 
		get : function( name ){
			var cookieName = encodeURIComponent(name) + '=',
				cookieStart = document.cookie.indexOf(cookieName),
				cookieValue = null;
			if(cookieName.length > 0){
				var cookieEnd = document.cookie.indexOf(";",cookieStart);
				if(cookieEnd == -1){
					cookieEnd = document.cookie.length;
				};
				cookieValue = decodeURIComponent(substring(cookieStart + cookieName.length,cookieEnd));
			};
			return cookieValue;
		},
		/*
		*  @ cookie设置
		*  参数说明：(cookie名称，cookie值，过期时间，路径，域名，安全性)
		*  返回：完整的cookie字符串
		*/ 
		set : function( name,value,expires,path,domain,secure ){
			var cookieStr = encodeURIComponent(name) + "=" + encodeURIComponent(value);
			if(expires instanceof Date){
				cookieStr += " ;expires=" + expires.toGMTString();
			};
			if(path){
				cookieStr += " ;path=" + encodeURIComponent(path);
			};
			if(domain){
				cookieStr += " ;domain=" + encodeURIComponent(domain);
			};
			if(secure){
				cookieStr += " ;secure"
			};
			document.cookie = cookieStr;
		},
		/*
		*  @ cookie删除
		*  参数说明：(cookie名称，cookie值，路径，域名，安全性)
		*  返回：完整的cookie字符串
		*/ 
		del : function(name,value,path,domain,secure){
			this.set(name,"",new Date(0),path,domain,secure);
		}
	};
/*
* ============ 子cookie获取、设置 ============
*/ 
	kaka.$subCookie = {
		/*
		*  @ 子cookie获取（单个）
		*  参数说明：(cookie名称，子cookie名称)
		*  返回：指定子cookie的值
		*/ 
		get : function(name,subName){
			var subCookies = this.getAll(name);
			if(subCookies){
				return subCookies.subName;
			}else{
				return null;
			};
		},
		/*
		*  @ 子cookie获取（集合）
		*  参数说明：(cookie名称，子cookie名称)
		*  返回：指定cookie下子cookie的名值对（对象）
		*/ 
		getAll : function(name){
			var cookieName = encodeURIComponent(name) + '=',
				cookieStart = document.cookie.indexOf(cookieName),
				result = {};
			if(cookieName.length > 0){
				var cookieEnd = document.cookie.indexOf(";",cookieStart);
				if(cookieEnd == -1){
					cookieEnd = document.cookie.length;
				};
				var cookieValue = decodeURIComponent(substring(cookieStart + cookieName.length,cookieEnd));
				var tempobj = cookieValue.split("&"),
					len = tempobj.length,
					i = len;
				while(i >= 0){
					var cur = tempobj[i],
						curobj = cur.split("=");
					result[decodeURIComponent(curobj[0])] = result[decodeURIComponent(curobj[1])];
					i--;
				}
				return result;
			};
			return null;
		},
		/*
		*  @ 子cookie设置（单个）
		*  参数说明：(cookie名称，子cookie名称，子cookie值，过期时间，路径，域名，安全性)
		*  返回：无
		*/ 
		set : function(name,subName,subValue,expires,path,domain,secure){
			var subCookies = this.getAll(name) || {};
			subCookies.subName = subValue;
			this.setAll(name,subCookies,expires,path,domain,secure);
		},
		/*
		*  @ 子cookie设置（集合）
		*  参数说明：(cookie名称，子cookie集，过期时间，路径，域名，安全性)
		*  返回：无
		*/ 
		setAll : function(name,subCookies,expires,path,domain,secure){
			var cookieText = encodeURIComponent(name) + "=",
				tempArr=[];
			for(var subName in subCookies){
				var cur = subCookies[subName];
				tempArr.push(encodeURIComponent(subName) + "=" + encodeURIComponent(cur));
			};
			if(tempArr.length > 0){
				var str = tempArr.join("&");
				cookieText += str;
				if(expires instanceof Date){
					cookieText += "; expires=" + expires.toGMTString();
				};
				if(path){
					cookieText += "; path=" + path;
				};
				if(domain){
					cookieText += "; domain=" + domain;
				};
				if(secure){
					cookieText += "; secure";
				};
			}else{
				cookieText += "; expires=" + (new Date(0)).toGMTString();
			};
			document.cookie = cookieText;
		},
		/*
		*  @ 子cookie删除
		*  参数说明：(cookie名称，子cookie名称，路径，域名，安全性)
		*  返回：无
		*/ 
		del : function(name,subName,path,domain,secure){
			var subCookies = this.getAll(name);
			delete subCookies.subName;
			this.setAll(name,subCookies,null,path,domain,secure);
		}
	};
/*
* ============ Ajax ============
*/ 
	kaka.$ajax = {
		/*
		*  @ 创建XHR对象
		*/ 
		getXHR : function(){
			if(typeof XMLHttpRequest != 'undefined'){
				return new XMLHttpRequest();
			}else if(typeof ActiveXObject != 'undefined'){
				if(typeof arguments.callee.ActiveXString != "string"){
					var version = ["MSXML2.XMLHttp.6.0","MSXML2.XMLHttp.3.0","MSXML2.XMLHttp"];
					for(var i = 0,len = version.length; i < len; i++){
						try{
							var xhr	= new ActiveXObject(version[i]);
							arguments.callee.ActiveXString = version[i];
							return xhr;
						}catch(er){}
					};
				}
				return new ActiveXObject(arguments.callee.ActiveXString);
			}else{
				throw new Error("您的浏览器不支持XHR.");
			}
		}
	};
	
	/* @ 获取event对象 */ 
	kaka.$getEvent = function(event){
		return event ? event : window.event;
	};
	/* @ 获取事件目标 */ 
	kaka.$getTarget = function(event){
		return event.target || event.srcElement;
	};
	/* @ 取消事件默认动作 */ 
	kaka.$preventDefault = function(event){
		if(event.preventDefault){
			event.preventDefault();
		}else{
			event.returnValue = false;
		}
	};
	/* @ 阻止冒泡 */ 
	kaka.$stopPropagation = function(event){
		if(event.stopPropagation){
			event.stopPropagation();
		}else{
			event.cancelBubble = true;
		}
	};
	
/*
* ============ 字符串扩展 ============
*/ 
	kaka.$str = {
		/*
		*  @ 清除头尾空格
		*/ 
		trim : function(str){
			return str.replace(/^\s*(.*?)\s*$/g,"$1");
		}
	};
/*
* ============ 数组扩展 ============
*/ 
	kaka.$arr = {
		/*
		*  @ 二分查找(仅针对排序后的数组，大数据量时很有用)
		*/ 
		binarySearch : function( arr,value ){
			var left = 0,
				right = arr.length,
				center = 0; 
			while( left <= right ){ 
				center = Math.floor((left + right) / 2); 
				if(value < arr[center]){ 
					right = center - 1; 
				}else{ 
					left = center + 1; 
				};
			};
			//未找到值时返回-1
			return (arr[center] == value) ? center : -1;
		},		
		/*
		*  @ 删除拥有指定值的项(支持多项)
		*/ 
		remove : function( arr,value ){
			var self = arr;
			//若无参数，则不做操作
			if( arguments.length <= 1 ){ return self };
			for(var i = 1,len = arguments.length;i < len; i++){
				var a = arguments[i];
				for( var j = 0 , leng = self.length ; j < leng ; j++ ){
					var b = self[j];
					if( a == b ){
						self.splice(j,1);
					};
				};
			}
			return self;
		},
		/*
		*  @ 去除数组重复值
		*/ 
		unique : function(arr){
			var obj = {}, len = arr.length;
			if( len < 2 ){return arr};
			for( var i = 0 ; i < len ; i++ ){
				var cur = arr[i];
				if( obj[cur] == undefined ){
					obj[cur] = 1;
				};
			};
			arr.length = 0;
			for( var name in obj ){
				arr[arr.length] = name;
			};
			return arr;
		}
	};
/*
* ============ 继承 ============
*/ 
	kaka.$inherit = {
		/*
		*  @ 原型继承 - 函数
		*  参数说明：（继承目标，子对象）
		*  Tip：前置操作
		*/ 
		funProto : function(parent,child){
			var F = function(){};
			F.prototype = parent.prototype;
			child.prototype = new F();
			child.prototype.constructor = child;
		},
		/*
		*  @ 原型继承 - 函数
		*  参数说明：（继承目标，子对象）
		*  Tip：前置操作
		*/ 
		funProto2 : function(parent){
			var F = function(){};
			F.prototype = parent.prototype;
			return new F();
		},
		/*
		*  @ 拷贝继承 - 函数
		*  参数说明：（继承目标，子对象）
		*/ 
		funCopy : function(parent,child){
			var p = parent.prototype,
				c = child.prototype;
			for(var i in p){
				c[i] = p[i];
			};
		},
		/*
		*  @ 深度拷贝 - 对象
		*  参数说明：继承目标
		*/ 
		deepCopy : function(p,c){
			var c = c || {};
			for(var i in p){
				if(typeof p[i] === 'object'){
					c[i] = p[i].constructor == Array ? [] : {};
					arguments.callee(p[i],c[i]);
				}else{
					c[i] = p[i];
				};
			};
			return c;
		}
	};
	
	// 赋作全局属性
	for( var pro in kaka ){
		if( pro.charAt(0) == '$' ){
			window[pro] = kaka[pro];
		};
	};
})(window);